package com.zhijiang.hospital.controller;

import cn.hutool.core.util.RandomUtil;
import com.alibaba.excel.EasyExcel;
import com.zhijiang.hospital.entity.OutpatientPerformanceEvaluation;
import com.zhijiang.hospital.entity.dto.OutpatientPerformanceEvaluationDto;
import com.zhijiang.hospital.service.OutpatientPerformanceEvaluationService;
import com.zhijiang.util.BaseQuery;
import com.zhijiang.util.Result;
import com.zhijiang.util.TimeUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2022-10-26 10:33:54
 */
@Api(tags = "门诊绩效考核接口")
@RestController
@RequestMapping("OutpatientPer")
//@PreAuthorize("hasAnyAuthority('admin','test','system:dept:test')")
public class OutpatientPerformanceEvaluationController {
    @Autowired
    private OutpatientPerformanceEvaluationService outpatientPerformanceEvaluationService;


    @ApiOperation("分页查询所有门诊绩效考核接口")
    @ApiModelProperty(value = "分页查询所有门诊绩效考核接口")
    @PostMapping("selectAll")
    public Result loadPageList(@RequestBody BaseQuery baseQuery) {
        return Result.ok(outpatientPerformanceEvaluationService.loadPageList(TimeUtil.initBaseQuery(baseQuery)));
    }


    //@ApiModelProperty(value = "查询所有的科室名称")
    //@GetMapping("dept")
    //public Result loadDept(){
    //    return Result.ok(outpatientPerformanceEvaluationService.loadDept());
    //}
    @ApiOperation("门诊运行Excel导出数据接口")
    @ApiModelProperty(value = "门诊运行Excel导出数据接口")
    @GetMapping("loadExcel")
    public void loadExcel(HttpServletResponse response) throws IOException {
        List<OutpatientPerformanceEvaluationDto> list = outpatientPerformanceEvaluationService.findAll();
        String title = "住院运行数据";
        // 告诉浏览器用什么软件可以打开此文件
        response.setHeader("content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        // 下载文件的默认名称
        response.setHeader("Content-Disposition", "attachment;filename=" + RandomUtil.randomNumbers(4) + URLEncoder.encode("住院运行数据.xlsx", "utf-8"));
        //4. 创建输入、输出流
        EasyExcel.write(response.getOutputStream(), OutpatientPerformanceEvaluationDto.class).sheet(title).doWrite(list);
    }

    @ApiOperation("分页查询所有门诊绩效考核接口")
    @ApiModelProperty(value = "分页查询所有门诊绩效考核接口")
    @GetMapping("loadDoctorNumberOfYear")
    public Result<List<OutpatientPerformanceEvaluation>> loadDoctorNumberOfYear() {
        return Result.ok(outpatientPerformanceEvaluationService.outpatientPerformanceEvaluation());
    }


}
